<?php
namespace Admin\Controller;
use Think\Controller;


class LoginController extends Controller {

    public function verify(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;  
        $Verify->length   = 4;  
        $Verify->useNoise = false;  
        $Verify->codeSet = '0123456789';  
        $Verify->imageW = 130;  
        $Verify->imageH = 50;  
        $Verify->entry(1);        
    }

    public function index(){

        if ($username) {
           $this->redirect(U('Admin/Admin/index')); 
        }else{
           $this->display();
        }

    }

    public function login(){


            if (!check_verify(I('verify',''),1)) {

                $this->redirect(U('Admin/Login/index'));

            }else{

                $username = I('username','');
                $password = md5(md5(I('password','')));                
                $Admin = M('admin');
                $map['username'] = $username;
                $map['password'] = $password;
                $result = $Admin->where($map)->select();
    
                
    
                if(empty($result)){
                     $this->error('账号或密码错误');
                }else{                
                   
                $data['loginip'] = get_client_ip();
                $data['logintime'] = time();
                $Admin->where(array('username' => $username))->save($data);

                session('username',$username);
                $Auth = M('auth_group_access');
                $role = $Auth->where(array(uid => $result[0]['id']))->select();
                session('auth',$role[0]['group_id']);

                $this->success('登陆成功',U('Admin/Index/index'));
                }
            }
        }

    public function logout(){
    	session('username',null); 
    	$this->success('退出成功',U('Admin/Login/index'));
    }
}